package com.example.compreshensiveshop.service.imp;

import com.example.compreshensiveshop.dao.CustomerDao;
import com.example.compreshensiveshop.dto.CustomerUpdateDTO;
import com.example.compreshensiveshop.po.CustomerPO;
import com.example.compreshensiveshop.service.CustomerService;
import com.example.compreshensiveshop.vo.CustomerMessageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Customer Service Implementation
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;

    @Override
    public CustomerMessageVO queryMessage(Long customerId) {
        CustomerPO customerPO = customerDao.queryMessage(customerId);
        return CustomerMessageVO.builder()
                .id(customerPO.getId())
                .nickname(customerPO.getNickname())
                .avatarUrl(customerPO.getAvatarUrl())
                .address(customerPO.getAddress())
                .birthday(customerPO.getBirthday())
                .gender(customerPO.getGender())
                .build();
    }

    @Override
    public void updateMessage(CustomerUpdateDTO customerUpdateDTO) {
        CustomerPO customerPO = CustomerPO.builder()
                .id(customerUpdateDTO.getId())
                .nickname(customerUpdateDTO.getNickname())
                .avatarUrl(customerUpdateDTO.getAvatarUrl())
                .address(customerUpdateDTO.getAddress())
                .birthday(customerUpdateDTO.getBirthday())
                .gender(customerUpdateDTO.getGender())
                .build();
        customerDao.updateMessage(customerPO);
    }

    @Override
    public void updateAvatar(Long customerId, String avatarUrl) {
        customerDao.updateAvatar(customerId, avatarUrl);
    }

    @Override
    public CustomerPO queryById(Long customerId) {
        return customerDao.queryById(customerId);
    }

    @Override
    public Long queryCustomerId(Long id) {
        return customerDao.queryCustomerId(id);
    }

    @Override
    public void addCustomer(Long id) {
        customerDao.addCustomer(id);
    }

    @Override
    public CustomerMessageVO queryByUserId(Long userId) {
        Long customerId = queryCustomerId(userId);
        return queryMessage(customerId);
    }

    @Override
    public String queryCustomerAddress(Long customerId) {
        return customerDao.queryCustomerAddress(customerId);
    }

    @Override
    public String queryMessageById(Long customerId) {
        CustomerPO  customerPO = customerDao.queryMessage(customerId);
        return customerPO.getNickname();
    }


}